<template>
    <div>
        <div class="head">
            首页 &nbsp;/ &nbsp;
            <span>套餐管理</span>
        </div>
        <div class="searchBox">
            <el-input placeholder="请输入搜索关键字" v-model="input" clearable></el-input>
            <button class="search">搜索</button>
            <button class="search" @click="goAdd">
                <i class="el-icon-circle-plus-outline" ></i> 添加
            </button>
        </div>
        <el-table :data="recipe" border style="width:1202px;">
            <el-table-column
                prop="_id"
                label="套餐编号"
                width="240"
                header-row-style="text-align: center;"
            ></el-table-column>
            <el-table-column prop="name" label="名称" width="240"></el-table-column>
            <el-table-column prop="normalPrice" label="价格" width="240"></el-table-column>
            <el-table-column prop="salePrice" label="打折价格" width="240"></el-table-column>
            <el-table-column label="操作" width="240">
                <template slot-scope="scope">
                   <div class="a1">
                        <button class="change" @click="changeRecipe(scope.row.name,scope.row.normalPrice,scope.row.salePrice,scope.row.mouth,scope.row.type,scope.row._id)">修改</button>
                   <button class="del" @click="delRecipeId(scope.row._id)">删除</button>
                   </div>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next" :total="100"></el-pagination>
    </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const {  mapState, mapActions ,mapMutations} = createNamespacedHelpers("recipeModules");
export default {
    data() {
        return {
            input: ''
        }

    },
    created(){
         this.asyncGetAllRecipe()
    },
    methods:{
        ...mapMutations(['getRecipeId']),
       ...mapActions(['asyncGetAllRecipe','asyncDelRecipe']),
       goAdd(){
           this.$router.push('/home/addRecipe')
       },
       delRecipeId(_id){
           console.log(_id);
           this.asyncDelRecipe({_id:_id})
       },
       changeRecipe(name,normalPrice,salePrice,mouth,type,_id){
           const arr={
                name,
                normalPrice,
                salePrice,
                mouth,
                type,
                _id
              

            }
            console.log(arr);
           this.getRecipeId(arr)
         
           this.$router.push('/home/changeRecipe')
       }
    },
    computed:{
         ...mapState(['recipe'])
    }
}
</script>

<style scoped lang="scss">
.head {
    width: 1250px;
    height: 80px;
    border-bottom: 1px solid #ccc;
    text-align: left;
    line-height: 70px;
    font-size: 20px;
    color: #a4a4a4;
    span {
        color: black;
        font-weight: 600;
    }
}
.searchBox {
    width: 1250px;
    height: 100px;
    line-height: 100px;
    text-align: left;
    
}
.el-input {
    width: 300px;
    vertical-align: middle;
}
.search {
    width: 80px;
    height: 40px;
    background-color: #1891ff;
    font-size: 19px;
    color: #fff;
    border: none;
    vertical-align: middle;
    margin-right: 10px;
    
    
}
.change {
    width: 80px;
    height: 40px;
    background-color: #1891ff;

    color: #fff;
    border: none;
   
}
.del {
    width: 80px;
    height: 40px;
    background-color: #fe4d4e;
    color: #fff;
    border: none;
}
.a1{
 
    width: 200px;
    display: flex;
    justify-content: space-around;

}

</style>